import React, { Component } from 'react'

function withLoading(WrappedComponent){
  return class extends WrappedComponent{
    render(){
      if(this.props.loading){
        return <div>loading...</div>
      }else{
        return super.render()
      }
    }
  }
}

class Demo extends Component {
  render() {
    return <h1>Demo组件</h1>
  }
}

let LoadingDemo = withLoading(Demo)

export default class App extends Component {
  state = {
    loading: true
  }
  componentDidMount() {
    setTimeout(()=>{
      this.setState({
        loading: false
      })
    }, 3000)
  }
  render() {
    return (
      <div>
        <h1>App组件</h1>
        <LoadingDemo
        loading={this.state.loading}></LoadingDemo>
      </div>
    )
  }
}
